import { computed, ref } from 'vue'
import { allViewType, opType } from './imgTypes'

const activeOpRef = ref<opType>({
  type: '',
  subType: ''
})

function setActiveOp(activeOp: opType) {
  if (activeOpRef.value.type !== '' && activeOpRef.value.subType !== '' && activeOp.type === activeOpRef.value.type && activeOp.subType === activeOpRef.value.subType) {
    Object.assign(activeOpRef.value, {
      type: '',
      subType: ''
    })
  } else {
    if (activeOp.type === 'line' || activeOp.type === 'angle' || activeOp.type === 'rectangle' || activeOp.type === 'ellipse') {
      Object.assign(activeOpRef.value, {
        type: 'measure',
        subType: activeOp.type
      })
    } else {
      Object.assign(activeOpRef.value, activeOp)
    }
  }
}

const isPlayingStatus = computed(() => {
  return activeOpRef.value.type === 'play'
})

const activeViewTypeRef = ref<allViewType | ''>('')

function setActiveViewType(viewType: allViewType) {
  activeViewTypeRef.value = viewType
}


export const useOpAndViewStatus = () => {
  return {
    activeOpRef,
    setActiveOp,
    isPlayingStatus,
    activeViewTypeRef,
    setActiveViewType
  }
}
